<?PHP

//tell we want to work with sessions
session_start();

$sesid = $_SESSION[sesid];

if (empty($sesid)) { header ("Location: ../login.php?do=m&e=24"); die(); } else {

include ($_SESSION["set_bpath"]."config.php");
$m = $_GET["m"];
$e = $_GET["e"];

if ($m == "") { $m = "14"; }






$get_logs = "SELECT * FROM `".$DBprefix."logs` WHERE `log_sesid` = '$sesid' AND `log_status` = 'ACTIVE'";  
$exexute_get_logs = mysql_query($get_logs); 

if ($log = mysql_fetch_array($exexute_get_logs)){
$log_id = $log["log_id"];
$log_userid = $log["log_userid"];
$log_ip = $log["log_ip"];
$log_date = $log["log_date"];
$log_sesexp = $log["log_sesexp"];
$log_sesid = $log["log_sesid"];


$check_logs = "SELECT * FROM `".$DBprefix."logs` WHERE `log_sesid` = '$sesid' AND `log_status` = 'LOGGEDOUT'";  
$exexute_check_logs = mysql_query($check_logs); 
if ($check_log = mysql_fetch_array($exexute_check_logs)){

} else {
$end_log = "INSERT INTO `".$DBprefix."logs` (`log_action`,`log_userid`,`log_page_to`,`log_page_from`,`log_ip`,`log_date`,`log_outdate`, `log_status`,`log_sesexp`,`log_sesid`) VALUES ('LOGGEDOUT','$log_userid','$info_current_url','$inf_reffered_url','$info_ipaddr','$timedate','$timedate','EXPIRED',0,'$log_sesid')";  
$exexute_end_log = mysql_query($end_log); 
}



$logout = "UPDATE `".$DBprefix."logs` SET `log_status` = 'EXPIRED' WHERE `log_sesid` = '$sesid'";  
$execute_logout = mysql_query($logout); 

}
}
// remove all files in the temp directory
$dir = "./temp/";
foreach(glob($dir."*.*") as $temp_file){
    unlink($temp_file);
}

//remove the session itself
unset($_SESSION[user_name]);
unset($_SESSION[user_pass]);
unset($_SESSION[sesid]);
session_destroy();


//echo " You Have been logged out properly!!   <a href='../login.php'>Continue</a>";

				// TRANSFER TO A FINAL DESTINATION AFTER GOOD LOGIN.
				//echo "INSERT INTO `".$DBprefix."logs` (`log_action`,`log_userid`,`log_page_to`,`log_page_from`,`log_ip`,`log_date`,`log_indate`, `log_status`,`log_sesexp`,`log_sesid`) VALUES ('LOGIN','$user_id','$info_current_url','$inf_reffered_url','$info_ipaddr','$timedate','$timedate','ACTIVE','$sesxp','$make_sesid')";
				if ($conf_alou == "2") {					
					header("Location: $conf_weburl?do=m&m=$m");
				} else if ($conf_alou == "1") {
					header("Location: ".$conf_acpurl."login.php?do=m&m=$m");
				} else {
					header("Location: ../login.php?do=m&m=$m");
				}

?>